#pragma once
#include <iostream>
#include <string>
#include <sys/ipc.h>
#include <sys/shm.h>
const int size = 4096;
const std::string pathname = "/home/czf/less/len/nameProcessPool/slvm";
const int proj_id = 0x11223344;
key_t getkey()
{
    key_t key = ftok(pathname.c_str(), proj_id);
    if (key < 0)
    {
        std::cerr << "errno:" << errno << ",errstring" << strerror(errno) << std::endl;
        exit(1);
    }

    return key;
}
std::string tohex(int id)
{
    char buffer[1024];
    snprintf(buffer, sizeof(buffer), "0x%x", id);
    return buffer;
}
int CreateShmHelper(key_t key, int flag)
{
    int shmid = shmget(key, size, flag);
    if (shmid < 0)
    {
        std::cerr << "errno:" << errno << ",errstring" << strerror(errno) << std::endl;
        return 1;
    }
    return shmid;
}
int CreateShm(key_t key)
{
    return CreateShmHelper(key, IPC_CREAT | IPC_EXCL | 0644);
}
int GeteShm(key_t key)
{
    return CreateShmHelper(key, IPC_CREAT);
}